<template>
  <div class="home">
    <header-img />
    <covid-info :CovidInfo="CovidInfos" />
    <case-num :CaseNumData="CaseNumData" />
    <the-map />
    <info-swiper />
    <spring-travel />
    <the-news :NewsData='NewsData' />
  </div>
</template>

<script>
import api from '../api/index'
import HeaderImg from '@/components/HeaderImg.vue'
import CovidInfo from '@/components/CovidInfo.vue'
import CaseNum from '@/components/CaseNum.vue'
import TheMap from '@/components/TheMap.vue'
import InfoSwiper from '../components/InfoSwiper.vue'
import SpringTravel from '../components/SpringTravel.vue'
import TheNews from '../components/TheNews.vue'
export default {
  data () {
    return {
      CovidInfos: {
        note1: '',
        note2: '',
        note3: '',
        remark1: '',
        remark2: '',
        remark3: ''
      },
      CaseNumData: {
        modifyTime: '',
        currentConfirmedCount: '', // 现存确诊人数
        confirmedCount: '', // 累计确诊人数
        suspectedCount: '', // 累计境外输入人数
        curedCount: '', // 累计治愈人数
        deadCount: '', // 累计死亡人数
        seriousCount: '', // 现存无症状人数

        suspectedIncr: '', // 新增境外输入人数
        currentConfirmedIncr: '', // 相比昨天现存确诊人数
        confirmedIncr: '', // 相比昨天累计确诊人数
        curedIncr: '', // 相比昨天新增治愈人数
        deadIncr: '', // 相比昨天新增死亡人数
        seriousIncr: '' // 相比昨天现存无症状人数
      },
      NewsData: []
    }
  },
  components: {
    HeaderImg,
    CovidInfo,
    CaseNum,
    TheMap,
    InfoSwiper,
    SpringTravel,
    TheNews
  },
  mounted () {
    api.getData('/xiaoniu/data/data/overall.json').then((res) => {
      if (res.status === 200) {
        const { note1, note2, note3, remark1, remark2, remark3 } =
          res.data.results[0]
        note1 ? (this.CovidInfos.note1 = note1) : (this.CovidInfos.note1 = '')
        note2 ? (this.CovidInfos.note1 = note2) : (this.CovidInfos.note2 = '')
        note3 ? (this.CovidInfos.note1 = note3) : (this.CovidInfos.note3 = '')
        remark1
          ? (this.CovidInfos.remark1 = remark1)
          : (this.CovidInfos.remark1 = '')
        remark2
          ? (this.CovidInfos.remark2 = remark2)
          : (this.CovidInfos.remark2 = '')
        remark3
          ? (this.CovidInfos.remark3 = remark3)
          : (this.CovidInfos.remark3 = '')
      }
    })
    api
      .getNcov({
        key: 'b417fdb3af8a56ba42db3604c3d694d5'
      })
      .then((res) => {
        if (res.status === 200) {
          const {
            modifyTime,
            currentConfirmedCount,
            confirmedCount,
            suspectedCount,
            curedCount,
            deadCount,
            seriousCount,
            suspectedIncr,
            currentConfirmedIncr,
            confirmedIncr,
            curedIncr,
            deadIncr,
            seriousIncr
          } = res.data.newslist[0].desc
          this.CaseNumData.modifyTime = modifyTime
          this.CaseNumData.currentConfirmedCount = currentConfirmedCount
          this.CaseNumData.confirmedCount = confirmedCount
          this.CaseNumData.suspectedCount = suspectedCount
          this.CaseNumData.curedCount = curedCount
          this.CaseNumData.deadCount = deadCount
          this.CaseNumData.seriousCount = seriousCount
          this.CaseNumData.suspectedIncr = suspectedIncr
          this.CaseNumData.currentConfirmedIncr = currentConfirmedIncr
          this.CaseNumData.confirmedIncr = confirmedIncr
          this.CaseNumData.curedIncr = curedIncr
          this.CaseNumData.deadIncr = deadIncr
          this.CaseNumData.seriousIncr = seriousIncr
          // 新闻
          this.NewsData = res.data.newslist[0].news
        }
      })
  }
}
</script>
<style scoped>
.home {
  overflow: hidden;
}
</style>
